package yahtzee;

import java.util.*;
import java.io.*;
/*
 * Problem ID: 110208
 * Algorithm: Let's attempt another backtracking solution!
 */
class Main 
{
	public static void main(String [] args)
	{
		new Yahtzee().start();
	}
}

class Yahtzee
{
	public void start()
	{
		// Create BufferedReader.
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		
		try
		{
			String [] diceRolls = new String [14];
			ScoreCard [] solutionArray;
			ScoreCard [] cards;
			
			String roundResults = "";
			int roundCounter = 1;
			
			while ((roundResults = reader.readLine()) != null)
			{
				diceRolls[roundCounter] = sortString(roundResults);
				
				roundCounter++;
				
				if (roundCounter == 14)
				{
					solutionArray = new ScoreCard[14];
					
					cards = createScoreCard();
					
					// Perform backtracking here.
					backtrack(solutionArray, cards, diceRolls, 0, 0);
					
					roundCounter = 1;
					diceRolls = new String[14];
				}
			}
		}
		catch (IOException ex)
		{
			ex.printStackTrace();
		}
	}
	
	public void backtrack(ScoreCard [] solutionArray, ScoreCard [] cardTypes, String [] diceRolls, int k, int totalScore)
	{
		ScoreCard [] candidates = new ScoreCard [13];
		int numOfCandidates;
		
		if (isSolution(solutionArray, totalScore))
		{
			printSolution(solutionArray, cardTypes, totalScore);
		}
		else
		{
			k++;
		}
	}
	
	public int constructCandidates(ScoreCard [] cardTypes, String [] diceRolls, ScoreCard [] candidates, int k, int totalScore)
	{
		int [] rollTypes;
		int sum = 0;
		ScoreCard [] kinds;
		
		// Verify the possible score cards a dice roll can have.
		String diceResults = diceRolls[k];
			
		// Search for values of the first six rules and return how many are there.
		rollTypes = search(diceResults);
		
		// Search for values of the remaining rules.
		kinds = searchAllKinds(diceResults, cardTypes);
		
		// Retrieve the total sum from first six rules.
		for (int i = 1; i < rollTypes.length; i++)
		{
			sum += rollTypes[i] * i;
			
			if (sum >= totalScore)
			{
				// Retrieve card and add it as candidate.
				ScoreCard card = cardTypes[i];
			
				if (!card.isUsed())
				{
					candidates[i - 1] = card;
				}
			}
		}
		return 0;
	}
	
	public ScoreCard [] searchAllKinds(String diceResults, ScoreCard [] cardTypes)
	{
		int sum = 0;
		
		int [] results = search(diceResults);
		
		ScoreCard [] values = new ScoreCard[7];
		
		for (int i = 1; 1 < results.length; i++)
		{
			if (results[i] == 3)
			{
				//Three of a kind.
				values[i] = cardTypes[8];
			}
			if (results[i] == 4)
			{
				// Four of a kind.
				values[i] = cardTypes[9];
			}
			if (results[i] == 5)
			{
				// Five of a kind.
				values[i] = cardTypes[10];
			}
		}
		
		return values;
	}
	
	public int [] search(String diceResults)
	{
		int [] countTable = new int[7];
		
		for (int i = 0; i < diceResults.length(); i++)
		{
			int value = Integer.parseInt(diceResults.charAt(i) + "");
			
			countTable[value] += 1;
		}
		
		return countTable;
	}
	
	public void printSolution(ScoreCard [] solutionArray, ScoreCard [] cards, int totalScore)
	{
		int bonus = 0;
		String result = "";
		
		// Check if the sum of the first six categories >= 63.
		if (checkForBonus(cards) == true)
		{
			bonus = 35;
		}
		
		for (int i = 1; i < solutionArray.length; i++)
		{
			result += solutionArray[i].getNumOfPoints() + " ";
		}
		
		System.out.println(result + " " + bonus + " " + (bonus + totalScore));
	}
	
	public boolean isSolution(ScoreCard [] solutionArray, int score)
	{
		int points = 0;
		
		// Determine if the solutionArray is filled.
		for (int i = 1; i < solutionArray.length; i++)
		{
			if (solutionArray[i] == null)
			{
				return false;
			}
		}
		
		// And calculate the total score.
		points = calculateScore(solutionArray);
		
		return (points >= score);
	}
	
	public int calculateScore(ScoreCard [] solutionArray)
	{
		ScoreCard card;
		int points = 0;
		
		for (int i = 1; i < solutionArray.length; i++)
		{
			// Retrieve scoreCard.
			card = solutionArray[i];
			
			// Retrieve points.
			points += card.getNumOfPoints();
		}
		return points;
	}
	
	public boolean checkForBonus(ScoreCard [] cards)
	{
		ScoreCard card;
		int counter = 0;
		int sum = 0;
		
		for (int i = 0; i < 6; i++)
		{
			card = cards[i];

			sum += card.getNumOfPoints();
			
			if (sum >= 63)
			{
				return true;
			}
		}
			
		return false;
	}
	
	public String sortString(String arg)
	{
		char [] stringToChar = arg.toCharArray();
		
		Arrays.sort(stringToChar);
		
		String sorted = String.valueOf(stringToChar);
		
		return sorted.trim();
	}
		
	public ScoreCard [] createScoreCard()
	{
		ScoreCard [] card = new ScoreCard[13];
		
		for (int i = 1; i < 14; i++)
		{
			// Create the score cards.
			card[i] = new ScoreCard(0, i);
		}
		
		return card;
	}
}

class ScoreCard
{
	private boolean used;
	private int numOfPoints;
	private int cardType;
	
	public ScoreCard(int numOfPoints, int cardType)
	{
		this.numOfPoints = numOfPoints;
		this.cardType = cardType;
	}
	
	public void setUsed(boolean used)
	{
		this.used = used;
	}
	
	public boolean isUsed()
	{
		return used;
	}
	
	public void setNumOfPoints(int numOfPoints)
	{
		this.numOfPoints = numOfPoints;
	}
	
	public int getNumOfPoints()
	{
		return numOfPoints;
	}
	
	public int getCardType()
	{
		return cardType;
	}
}